How to Use substring() with Regular Expressions

To extract a substring using a regular expression BigQuery provides the function regexp_substr, which receives a source string and a pattern with the regular expression. The function regexp_substr returns a substring matching the regular expression.

select regexp_substr('hello how are you', 'h[a-z]* ') as a_word_starting_with_h
a_word_starting_with_h
hello

Other interesting function is regexp_replace which can be used to match a substring with a regular expression, then replace it with another substring:

select regexp_replace('yellow submarine', 'y[a-z]*w','blue');
Regexp_replace
blue submarine

IN THIS PAGE